import { Component, OnInit } from '@angular/core';
import { DatadictionaryService } from 'src/app/service/datadictionary.service';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-membership',
  templateUrl: './membership.component.html',
  styleUrls: ['./membership.component.scss'],
  providers: [DatadictionaryService]
})
export class MembershipComponent implements OnInit {
  dataSet = [];
  loading = true;
  isOkLoading = false;
  isVisible = false;
  doc: any = {};
  data:any;
  constructor(private service: DatadictionaryService, private msg: NzMessageService) {
  }
  ngOnInit() {
    this.searchData();
  }

  searchData(): void {
    this.loading = true;
    this.service.queryBycode('membership').then((res) => {
      this.loading = false;
      this.data= res;
      this.dataSet = res.value;
    });
  }

  /**修改 */
  edit(data: any) {
    this.isVisible = true;
    this.doc = data;
  }

  handleOk(): void {
    this.isOkLoading = true;
    if (!this.doc.count || this.doc.count === '') {
      this.msg.warning('请设置数值！');
    }else {
      debugger
      var a=this.dataSet;
      this.service.save({
        _id: this.data._id,
        value: this.dataSet
      }).then((res) => {
        this.searchData();
        this.msg.success('保存成功！');
        this.isVisible = false;
        this.doc = {};
      });
    }
  }
  handleCancel(): void {
    this.isVisible = false;
    this.doc = {};
  }
}
